import  React,{Component} from 'react';
import {connect} from 'react-redux';
import {ListPageWrapper,ListLeft,ListRight} from "./style";
import ListContent from './components/ListContent';
import LeftBar from './components/LeftBar';
import {getContent} from "./store/actionCreators";
class ListPage extends Component{

    render(){
        return(
            <ListPageWrapper>
                <ListLeft><LeftBar checked={this.props.location.state?this.props.location.state.bar:null}/></ListLeft>
                <ListRight><ListContent checked={this.props.location.state?this.props.location.state.url:''}/></ListRight>
            </ListPageWrapper>
        )
    }
    componentDidMount(){//初始化   拿到url请求改变列表中的数据
        window.scrollTo(0,0);
        if (this.props.location.state) {
            this.props.changeGetContent(this.props.location.state.url);

        }else{
            this.props.history.push('/');
        }

    }
    componentWillReceiveProps(nextProps){

        const s=nextProps.location.state.url;

        this.props.changeGetContent(s);

    }
}
const mapDispatch=(dispatch)=>({
    changeGetContent(url){
        dispatch(getContent(url));
    }
});
export default connect(null,mapDispatch)(ListPage);